package com.yuneec.droneservice.command;

import android.util.Log;

import com.MAVLink.yuneec.msg_mav_rc_cmd_ack;
import com.yuneec.droneservice.model.CameraInfo;
import com.yuneec.droneservice.request.IResponse;

/**
 * Created by gjw on 2017/3/27.
 */

public class GetCameraInfo extends BaseCommand {

    public GetCameraInfo() {
        super(MAV_RC_COMMAND.MAV_RC_CMD_GET_CAMERA_INFO);
    }

    @Override
    protected short[] body() {
        return null;
    }

    @Override
    public IResponse<CameraInfo> toResponse(msg_mav_rc_cmd_ack ack) {
        int code = ack.code;
        IResponse<CameraInfo> response = new IResponse(ids(), code);
        Log.d("zzd_aoa", "GetCameraInfo:" + code);
        if (code == MAV_RC_ERROR_CODE.MAV_RC_ERR_SUCCESS) {
            try {
                CameraInfo cameraInfo = new CameraInfo();
                int index = 0;
                int ssidLen = uIntArrayToUShort(ack.params, index);
                index += 2;
                cameraInfo.setSsid(new String(uIntArrayToByteArray(ack.params, index, ssidLen)));
                index += ssidLen;
                int ipLen = uIntArrayToUShort(ack.params, index);
                index += 2;
                cameraInfo.setIp(new String(uIntArrayToByteArray(ack.params, index, ipLen)));
                index += ipLen;
                cameraInfo.setFrequency(uIntArrayToUShort(ack.params, index));
                index += 2;
                cameraInfo.setLevel(uIntArrayToShort(ack.params, index));
                Log.d("zzd_aoa", cameraInfo.toString());
                response.setParam(cameraInfo);
            } catch (Exception e) {
                Log.e("zzd_aoa", "getCameraInfo error:" + e.getMessage());
                response.setCode(MAV_RC_ERROR_CODE.MAV_RC_ERR_UNKNOW);
            }
        }
        return response;
    }

}
